<?php

class View
{

    private $path;
    private $vars = array();
    private $templateExtenstion = 'php';

    function __construct($path = null) {
        if ($path != null && file_exists($path) && is_dir($path)) {
            $this->path = $path;
        }
    }
    
    function setPath($path) {
        if (file_exists($path) && is_dir($path)) {
            $this->path = $path;
        }
    }
    
    function getPath() {
        return $this->path;
    }

    function assignArray(array $array) {
        $this->vars = array_merge($this->vars, (array)$array);
    }
    
    function assign($key, $value) {
        $this->vars[$key] = $value;
    }
    
    function remove($key) {
        if (isset($this->vars[$key])) {
            unset($this->vars[$key]);
        }
    }
    
    function removeAll() {
        $this->vars = null;
        $this->vars = array();
    }
    
    function render($template) {
        extract($this->vars);
        $template = str_replace(array('\\', '/'), DS, $template);
        require sprintf('%s%s%s.%s', $this->path, DS, $template, $this->templateExtenstion);
    }
    
}